﻿Imports DTO
Imports BUS

Public Class frmThemNCC

    Private Sub btn_them_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_them.Click
        If txt_diachi.Text <> "" And txt_TenNcc.Text <> "" And txtsdt.Text <> "" Then
            Dim ncc As New NhaCungCapDTO()
            ncc.TenNCC = txt_TenNcc.Text
            ncc.SDT = txtsdt.Text
            ncc.DiaChi = txt_diachi.Text
            ncc.MaLoai = cbb_tenloai.SelectedValue
            ncc.NgayCungCap = dtp_ngaycc.Value
            NhaCungCapBUS.THEM(ncc)
            LoadDSNCC()
            MessageBox.Show("Da Them Thanh Cong!")
        Else
            MessageBox.Show("Xin Nhap Day Du Thong Tin!", "Thông Báo")
        End If

    End Sub
    Private Sub LoadDSNCC()
        dgv_chitietncc.DataSource = NhaCungCapBUS.LAYTATCATT()
    End Sub
    Private Sub loadmaloa()
        cbb_tenloai.DataSource = LoaiBUS.LayTatCaTT()
        cbb_tenloai.DisplayMember = "TenLoai"
        cbb_tenloai.ValueMember = "MaLoai"
    End Sub
    Private Sub frmThemNCC_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        loadmaloa()
        LoadDSNCC()
    End Sub

    Private Sub btn_thoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_thoat.Click
        Me.Close()
    End Sub

    Private Sub btn_xoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_xoa.Click
        Dim dial = MessageBox.Show("Bạn Có Thật Sự Muốn Xóa Nhà Cung Cấp Này?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If dial = DialogResult.Yes Then
            Dim nv As New NhaCungCapDTO()
            Dim ma As Integer
            ma = dgv_chitietncc.Rows(temp).Cells(0).Value
            nv.MaNhaCungCap = ma
            NhaCungCapBUS.XOA(nv.MaNhaCungCap)
            LoadDSNCC()
            MessageBox.Show("Da Xoa Thanh Cong!")
        End If
       
    End Sub

    Private Sub cbb_maloai_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbb_tenloai.SelectedIndexChanged

    End Sub

    Private Sub btn_sua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_sua.Click
        Dim ncc As New NhaCungCapDTO()
        ncc.TenNCC = txt_TenNcc.Text
        ncc.SDT = txtsdt.Text
        ncc.DiaChi = txt_diachi.Text
        ncc.MaLoai = cbb_tenloai.SelectedValue
        ncc.NgayCungCap = dtp_ngaycc.Value
        ncc.MaNhaCungCap = dgv_chitietncc.Rows(temp).Cells(0).Value
        NhaCungCapBUS.CAPNHAP(ncc)
        LoadDSNCC()
        MessageBox.Show("Da Them Thanh Cong!")
    End Sub

    Private Sub btn_Nhaplai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Nhaplai.Click
        txt_diachi.Text = ""
        txtsdt.Text = ""
        txt_TenNcc.Text = ""
        cbb_tenloai.Text = ""
        dtp_ngaycc.Text = ""
    End Sub
    Dim temp As Integer
   

    Private Sub dgv_chitietncc_RowEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv_chitietncc.RowEnter
        temp = e.RowIndex

    End Sub
End Class